<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>编辑角色</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../bangnuo/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../bangnuo/admin/style/admin.css" media="all">
</head>

<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">角色名</label>
                    <div class="layui-input-block">
                        <input type="text" name="roleName" id="roleName" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <br/>
               <!-- <div class="layui-inline">
                    <label class="layui-form-label">唯一标识</label>
                    <div class="layui-input-block">
                        <input type="text" name="roleCode" id="roleCode" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>-->
                <label class="layui-form-label"></label>
                <input type="hidden" id="id" name="id" placeholder="" autocomplete="off" class="layui-input">
                <div class="layui-form-item">
                    <div class="layui-btn-container"
                         style="padding-bottom: 10px; margin-left: 110px; margin-right: -110px;">
                        <button class="layui-btn" lay-submit lay-filter="role-form" data-type="close">立即提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="../../../bangnuo/admin/layui/layui.js"></script>
<script type="text/javascript" src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
<!--获取id-->
<script type="text/javascript">
    $(document).ready(function () {
        //获取地址栏路径
        var url = window.location.href;
        //获取“=”的下标
        var pos = url.indexOf("=");
        //获取“=”后的全部字符（用户id）
        var id = url.substring(pos + 1, url.length);
        $.ajax({
            url: "/permissionsEntity/roleById/" + id,
            contentType: "application/json;charset=UTF-8",
            type: "GET",
            success: function (data) {
                $("#roleName").val(data.queryResult.list[0].roleName);
                // $("#roleCode").val(data.queryResult.list[0].roleCode);
                $("#id").val(data.queryResult.list[0].id);
            }
        });
    });
</script>
<!--执行修改-->
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        var $ = layui.$,
            form = layui.form,
            layer = layui.layer,
            index = parent.layer.getFrameIndex(window.name);

        //监听提交
        form.on('submit(role-form)', function (data) {
            $.ajax({
                type: "post",
                contentType: "application/json;charset=UTF-8",
                url: "/permissionsEntity/upRole",
                async: true,
                data: JSON.stringify(data.field),
                success: function (data) {
                    if (data.success == true) {
                        layer.msg(data.message);
                        $(document).ready(function () {
                            var  index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            console.log("index值",index);
                            close();
                            window.parent.location.reload();
                        });
                    } else {
                        layer.msg(data.message);
                    }
                }
            });
            return false;
        });

        function close() {
            var active = {
                close: function () {
                    parent.layer.msg('修改成功');
                    window.parent.location.reload();
                    parent.layer.close(index);
                }
            }
            $('.layui-btn-container .layui-btn').on('click', function () {
                var othis = $(this),
                    type = othis.data('type');
                active[type] && active[type].call(this);
            });
        }
    });
</script>

</html>